'use strict';
const jwt = require('jsonwebtoken');

module.exports = () => {
  return async (ctx, next) => {
    // 登录权限的校验
    const { authorization } = ctx.request.header;

    if (authorization) {
      jwt.verify(authorization, '1907A');

      await next();

    } else {
      ctx.status = 401;

      ctx.body = {
        code: 1,
        msg: '您还未登录，请先登录',
      };
    }
  };
};
